//
//  Test.hpp
//  Test01
//
//  Created by 张木林 on 6/30/25.
//

#ifndef Test_hpp
#define Test_hpp

#include <stdio.h>
#include <iostream>
#include <vector>
#include <unordered_map>
using namespace std;

class Solution
{
public:
    int findLHS(vector<int>& nums)
    {
        //用于统计每个数组出现的次数
        unordered_map<int, int>numCount;
        for(int num : nums)
        {
            numCount[num]++;
        }
        
        int maxLength = 0;
        //遍历哈希表 寻找值为1的两个数的出现次数之和的最大值
        for(auto& pair: numCount)
        {
            int currentNum = pair.first;
            //检查当前数字 + 1 是否在哈希表中
            if(numCount.find(currentNum+1)!= numCount.end())
            {
                maxLength = max(maxLength,pair.second + numCount[currentNum + 1]);
            }
        }
        return maxLength;
    }
};




class TwsSum
{
public:
    //1.两数之和的leetcode
    vector<int>twoSum(vector<int>&nums,int target)
    {
        vector<int>result;
        for(int i = 0;i<nums.size();i++)
        {
            for(int j = i+1;j<nums.size();j++)
            {
                if(nums[i] + nums[j] == target)
                {
                    result.push_back(i);
                    result.push_back(j);
                    return result;
                }
            }
        }
        return result;
    }
};


class groupAnagrams
{
  vector<vector<string>>GroupAnagrams(vector<string>&strs)
    {
      unordered_map<string,vector<string>>map;
      
      for(string str:strs)
      {
          string key = str;
          sort(key.begin(),key.end());
          map[key].push_back(str);
      }
      vector<vector<string>>result;
      for(auto& pair:map)
      {
          result.push_back(pair.second);
      }
      return result;
  }
    
};
#endif /* Test_hpp */
